﻿namespace TanzimSaqib.NoBrainer.Sample.Account
{
    using System;
    using System.Web.Security;
    using DataAccess;

    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

            // Create a blog for the user before redirection. 
            // Because we are not using MVC features here for demo purpose,
            // we are simply calling the repository. Note: really ugly code.
            ISingleRepository respository = new SingleRepository();
            respository.CreateBlog(RegisterUser.UserName);

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }

    }
}
